<template>
	<!-- 退出登录 -->
	<u-modal
	v-model="agreementVisible"
	:title="lang_once.agreeTitle"
	show-cancel-button
	:cancel-text="lang_once.disagreePolicy"
	:confirm-text="lang_once.agreePolicy"
	:confirm-color="'#FD1E43'"
	@confirm="agreePolicy"
	@cancel="closeApp"
	z-index="9999999"
	>
		<view class="u-p-20 u-f-28">
			{{ lang_once.agreeContent[0] }}
			<text class="color-primary" @click="jumpUrl('/pages/other/richText/richText?type=policy')">《{{ lang_once.policy }}》</text>{{ lang_common.and }}
			<text class="color-primary" @click="jumpUrl('/pages/other/richText/richText?type=privacy')">《{{ lang_once.privacy }}》</text>
			{{ lang_once.agreeContent[1] }}
		</view>
	</u-modal>
</template>

<script>
	import { AGREEMENT_NAME, GUIDE_NAME, USER_TYPE } from '@/config.js'
	export default {
		data() {
			return {
				agreementVisible: false
			}
		},
		onLoad() {
			// 判断是否已经同意协议
			let agreement = uni.getStorageSync(AGREEMENT_NAME)
			if (!agreement) {
				this.agreementVisible = true
			} else {
				// 如果已经同意协议并已经通过引导页，则进入广告页面
				let passGuide = uni.getStorageSync(GUIDE_NAME)
				if (!passGuide) {
					uni.reLaunch({
						url: '/pages/once/guide/guide'
					})
				} else if (this.userInfo.token) {
					uni.reLaunch({
						url: '/pages/once/ad/ad'
					})
					// let userType = uni.getStorageSync(USER_TYPE) || 'user'
					// uni.reLaunch({
					// 	url: `/pages/tabbar/${ userType }/index/index`
					// })
				}else {
					uni.reLaunch({
						url: '/pages/first/select/select'
					})
				}
			}
		},
		methods: {
			// 不同意协议并退出应用
			closeApp() {
				// #ifdef APP-PLUS
				switch (uni.getSystemInfoSync().platform) {
				  case 'android':
				    plus.runtime.quit();
				    break;
				  case 'ios':
				    plus.ios.import('UIApplication').sharedApplication().performSelector('exit');
				    break;
				}
				// #endif
			},
			// 同意协议并进入引导页
			agreePolicy() {
				uni.setStorageSync(AGREEMENT_NAME, 'ok')
				uni.reLaunch({
					url: '/pages/once/guide/guide'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	
</style>
